﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SelectSaveView : IUIView
{
    public Button  back;
    public Transform content;
    List<SaveInfoView> saveInfoViews;
    public override void Initinalize()
    {

        back.onClick.AddListener(()=> { Hide(); UIManager.Instance.mainPanel.Show(); });
        

    }
    public override void Hide()
    {
        base.Hide();

    }
    public override void Show()
    {
        AddGameMemeroy();
        base.Show();
    }
    /// <summary>
    /// 添加存档
    /// </summary>
    public void AddGameMemeroy()
    {
        List<SaveGameData> saveInfo= SaveGame.SaveInfo;
        if (saveInfoViews == null)
        {
            saveInfoViews = new List<SaveInfoView>();
        }
        if (saveInfo == null)
            return;
        for (int j = 1; j < content.childCount; j++)
        {
            content.GetChild(j).GetComponent<SaveInfoView>().Init(saveInfo[j - 1].title, saveInfo[j - 1]);
        }

            SaveInfoView saveItem = Resources.Load<SaveInfoView>("Prefabs/UI/Image");
        for (int i = content.childCount-1; i < saveInfo.Count; i++)
        {
            SaveInfoView infoView = Instantiate(saveItem, content);
            infoView.Init(saveInfo[i].title, saveInfo[ i]);
            saveInfoViews.Add(infoView);
        }



    }
    public List<SaveInfoView> GetAllSaveInfoView()
    {
        if (saveInfoViews != null)
        {
            return saveInfoViews;
        }
        int count= content.childCount;
        saveInfoViews = new List<SaveInfoView>();
        for (int i = 1; i < count; i++)
        {
            saveInfoViews.Add(content.GetChild(i).GetComponent<SaveInfoView>());
        }
        return saveInfoViews;
    }
}
